package com.stb.client.dialog;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class MessageBox {
	
	public static void alert(String title, String message) {
		final DialogBox dialog = new DialogBox();
		dialog.setText(title);
		dialog.setAnimationEnabled(true);
		VerticalPanel panel = new VerticalPanel();
		dialog.setWidget(panel);
		panel.add(new Label(message));
		final Button okButton = new Button("OK", new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				dialog.hide();
			}
		});
		panel.add(okButton);
		dialog.center();
		dialog.show();
		okButton.setFocus(true);
		okButton.addKeyDownHandler(new KeyDownHandler() {
			@Override
			public void onKeyDown(KeyDownEvent event) {
				if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
					okButton.click();
				}
			}
		});
	}
}
